//
// Created by Otowa_kotori on 2016/9/25.
//

#include "skill.h"
#include "entity.h"
#include "Game/Game.h"
#include "json/json.h"


bool Skill::use(Game *g, const std::vector<std::string> &params) {
    return true;
}

Json::Value Skill::toJson() {
    Json::Value root = PrefixObject::toJson();
    root["turn"] = this->turn;
    return root;
}

int Skill::range() {
    if (plainRange != -1){
        return plainRange;
    }
    else if (plainRange == -1 && origin->hasPrefix("_Actor_")){
        return std::stoi(origin->properties["attack_range"]);
    }
    else {
        return -1;
    }
}

bool CoolDownSkill::canUse(Game *g, const std::vector<std::string> &params) {
	if (!Skill::canUse(g, params)) return false;
    if (origin->properties["dead"] == "true") return false;
    if (origin->properties["ignore_cd"] == "true") return true;
	if (cd_timer > 0) return false;
	return true;
}

bool CoolDownSkill::use(Game *g, const std::vector<std::string> &params) {
	if(!Skill::use(g, params)) return false;
    cd_timer = cd;
	return true;
}

bool CoolDownSkill::onDescendCoolDown() {
    if((--cd_timer) < 0) cd_timer = 0;
    return true;
}

Json::Value CoolDownSkill::toJson() {
    Json::Value root = Skill::toJson();
    root["cd"] = this->cd;
    root["cd_timer"] = this->cd_timer;
    return root;
}
